package com.zyh.day05.operator

import org.apache.spark.sql.functions.col
import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession}

object WhereTest {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder()
      .master("local[*]")
      .appName("lt")
      .getOrCreate()

    val list = List((1, "xiaohei", 18, "F"), (2, "xiao2hei", 18, "F"), (3, "xiao3hei", 20, "M"), (4, "xiao4hei", 22, "M"))

    import spark.implicits._
    val df: DataFrame = list.toDF("uid", "name", "age", "sex")

    //val result: Dataset[Row] = df.where("uid>=3")
    //val result: Dataset[Row] = df.where((col("uid") >= 3).and(col("age") > 20))
    //val result: Dataset[Row] = df.where(col("uid")===1)
    val result: Dataset[Row] = df.where(col("uid")=!=1)

    result.show()
    spark.close()

  }
}
